@extends('layouts.default')
@section('css')
    <link rel="stylesheet" href="{{asset('admin-lte/plugins/datatables/dataTables.bootstrap4.css')}}">
    {{--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">--}}
    {{--<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">--}}
@stop

@section('content')
    <div class="row">
        <div class="col-12">
            
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">用户管理/ <a class="text-primary" href="{{url('admin/user/index')}}">用户列表</a></h3>
                </div>

                <div class="row">
                    <div style="width: 98.5%">
                        <div class="pull-right">
                            <div class="col-12">
                                <form action="#" class="form-inline" onsubmit="return false;">
                                    <div class="form-group">
                                        <label for="search_key">搜索类型：</label>
                                        <select class="form-control" id="search_key">
                                            @if(isset($search['key'])&&($search['key'] == 'user_name'))
                                                <option value="user_name" selected>用户名</option>
                                            @else
                                                <option value="user_name"  >用户名</option>
                                            @endif

                                            @if(isset($search['key'])&&($search['key'] == 'user_nickname'))
                                                    <option value="user_nickname" selected>昵称</option>
                                            @else
                                                    <option value="user_nickname" >昵称</option>
                                            @endif

                                        </select>
                                    </div>
                                    <div class="form-group" style="margin-left: 15px">
                                        <label for="search" class="sr-only">搜索关键字：</label>
                                        @if(!empty($search))
                                            <input type="text" class="form-control" id="search" style="text-align: left" placeholder="请输入搜索关键字" value="{{isset($search['val'])?$search['val']:''}}">
                                        @else
                                            <input type="text" class="form-control" id="search" style="text-align: left" placeholder="请输入搜索关键字" value="">
                                        @endif
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>

                @include('layouts.message')
                <!-- /.card-header -->
                <div class="card-body">
                    <table id="example1" class="table table-bordered table-striped">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>用户名</th>
                            <th>用户昵称</th>
                            <th>用户头像</th>
                            <th>用户性别</th>
                            <th>是否会员</th>
                            <th>注册时间</th>
                            <th>登录类型</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach ($lists as $list)
                        <tr>
                            <td>{{ $list['id'] }}</td>
                            <td>{{ $list['user_name'] }}</td>
                            <td>{{ $list['user_nickname'] }}</td>
                            <td><img style="max-width:60px!important;" src="{{ $list['user_avatar'] }}"></td>
                            <td>
                                @php
                                    if ( $list['user_sex']==1){echo '男';}else{echo '女';}
                                @endphp
                            </td>
                            <td>
                                @php
                                    if ( $list['is_vip']==1){echo '<span style="color:green;">是</span>';}else{echo '<span style="color:red;">否</span>';}
                                @endphp
                            </td>
                            <td>{{ $list['user_reg_time'] }}</td>
                            <td>{{ $list['login_type'] }}</td>

                            <td><a href="javascript:if(confirm('确认删除?')) location.href='{{url('admin/user/destroy',$list['id'])}}';" class="btn btn-danger">删除</a>
                                @if($list['is_disabled'] == 0)
                                    <a href="{{url('admin/user/disabled',$list['id'])}}" class="btn btn-info">禁用</a>
                                @else
                                    <a href="javascript:return false;" class="btn btn btn-default .disabled"  disabled="disabled">已禁用</a>
                                @endif
                                <a  class="btn btn-info" href="{{url('admin/user/rebateBenefit',$list['id'])}}">用户推荐</a>
                            </td>
                        </tr>
                        @endforeach
                        </tbody>
                        <tfoot>
                        <tr>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>
                        </tr>
                        </tfoot>
                    </table>

                </div>
                <!-- /.card-body -->
            </div>
            <!-- /.card -->
        </div>
        <!-- /.col -->
    </div>

@stop

@section('script')
    <script src="{{asset('admin-lte/plugins/datatables/jquery.dataTables.js')}}"></script>
    <script src="{{asset('admin-lte/plugins/datatables/dataTables.bootstrap4.js')}}"></script>
    <script>
        $(function () {
            $("#example1").DataTable({
                "language"  : {
                    url :'https://cdn.datatables.net/plug-ins/1.10.19/i18n/Chinese.json',
                },
                "lengthChange": false,
                "searching": false,
            });
            $('#search').keypress(function(e){
               e = e || window.event;
               if (e.keyCode==13){
                  let search_key            = $('#search_key').val();
                  let search_val            = $('#search').val();
                  let url                   = location.href;
                  url = url.split('?')[0];
                  if (!search_key           == '' && search_val!== ''){
                      let newUrl            = `${url}?${search_key}=${search_val}`;
                      location.href          =   newUrl;
                  }else {
                      location.href          =   url;
                  }
               }
            })
        });


    </script>
@stop